<template>
	<view>
		<navbar title="我的贷款" :autoBack="true"></navbar>
		<u-loading-page :loading="loading"></u-loading-page>
		<scroll-view scroll-y="true" class="scbox" v-if="!loading">
			<view class="con">
				<!-- 贷款额度 -->
				<view class="u-flex u-flex-x-center">
					<arprogress v-if="info.totalCredit" :percent="info.totalCredit/info.creditAmount" bgColor='transparent' activeColor='#3262FD' inactiveColor='#ccc'
						borderWidth='46' width='400'>
						<view class="">
							<view class="tip">
								可用额度(元)
							</view>
							<view class="num">
								{{info.totalCredit}}
							</view>
						</view>
					</arprogress>
				</view>
				<view class="info">
					<view class="info__box">

						<image src="/static/daikuan/boxbg.png" class="info__box__bg" mode=""></image>
						<view class="info__box__yuan1">

						</view>
						<view class="info__box__yuan2">

						</view>
						<view class="info__box__con">
							<view class="info__box__con__item">
								<view class="info__box__con__item__num">
									{{info.creditAmount}}
								</view>
								<view class="info__box__con__item__text">
									总额度(元)
								</view>
							</view>
							<view class="info__box__con__line">

							</view>
							<view class="info__box__con__item">
								<view class="info__box__con__item__num">
									{{info.creditAmount-info.totalCredit}}
								</view>
								<view class="info__box__con__item__text">
									已用额度(元)
								</view>
							</view>
						</view>
					</view>

				</view>
				<view class="u-flex u-flex-xy-center" style="padding-bottom: 30rpx;">
					<view class="info__item">
						<image src="/static/daikuan/hkgl.png" class="info__item__icon" mode=""></image>
						提前还款
					</view>
					<view class="info__line">

					</view>
					<view class="info__item" @click="navto('/pages/examine/loanapplication')">
						<image src="/static/daikuan/jk.png" class="info__item__icon" mode=""></image>
						借款申请
					</view>
				</view>
				<u-gap height="22rpx" bgColor="#F5F5F5"></u-gap>
				<view class="con__box">
					<view class="con__box__tabs">
						<view class="con__box__tabs__item" @click="curindex=index" v-for="(item,index) in tablist"
							:key="index" :class="curindex==index?'active':''">
							{{item.name}}
						</view>
					</view>
					<!-- 列表还款记录 -->
					<view class="con__box__list" v-if="curindex==0&&info.repayment">
						<view class="" v-if="info.repayment.length>0">
							<view class="con__box__list__item" v-for="(item,index) in info.repayment" :key="index">
								<view class="u-flex u-flex-y-center con__box__list__item__top" @click="item.zk=!item.zk,$forceUpdate()"
									:class="item.zk?'bb0':''">
									<view class="">
										<view class="con__box__list__item__name">
											还款
										</view>
										<view class="con__box__list__item__time">
											<!-- repayment -->
											{{$u.timeFormat(item.repayment, 'yyyy-mm-dd hh:MM:ss')}}
										</view>
									</view>
									<view class="u-flex u-flex-y-center">
										<view class="con__box__list__item__num u-flex u-flex-y-center">
											¥{{(item.price+item.faxi)||0}}
											<image src="/static/daikuan/xia.png" class="con__box__list__item__num__icon"
												:class="item.zk?'zk':''" mode=""></image>
										</view>
									</view>
								</view>
								<!-- 详情 -->
								<view class="con__box__list__item__box" v-if="item.zk">
									<view class="con__box__list__item__box__item">
										<view class="">
											还款金额
										</view>
										<view class="">
											¥{{item.price||0}}
										</view>
									</view>
									<view class="con__box__list__item__box__item">
										<view class="">
											本金
										</view>
										<view class="">
											¥{{item.benjin||0}}
										</view>
									</view>
									<view class="con__box__list__item__box__item">
										<view class="">
											利息
										</view>
										<view class="">
											¥{{item.lixi||0}}
										</view>
									</view>
									<view class="con__box__list__item__box__item">
										<view class="">
											罚息
										</view>
										<view class="">
											¥{{item.faxi||0}}
										</view>
									</view>
								</view>
							</view>
						</view>
						<u-empty v-else></u-empty>
					</view>
					
					<!-- 借款列表 -->
					<view class="con__box__list" v-if="curindex==1&&info.credit">
						<view class="" v-if="info.credit.length>0">
							<view class="con__box__list__item" v-for="(item,index) in info.credit" :key="index">
								<view class="u-flex u-flex-y-center con__box__list__item__top" @click="item.zk=!item.zk,$forceUpdate()"
									:class="item.zk?'bb0':''">
									<view class="">
										<view class="con__box__list__item__name">
											借款
										</view>
										<view class="con__box__list__item__time">
											{{item.loan_date}}
										</view>
									</view>
									<view class="u-flex u-flex-y-center">
										<view class="con__box__list__item__num u-flex u-flex-y-center">
											¥{{item.amount}}
											<image src="/static/daikuan/xia.png" class="con__box__list__item__num__icon"
												:class="item.zk?'zk':''" mode=""></image>
										</view>
									</view>
								</view>
								<!-- 详情 -->
								<view class="con__box__list__item__box" v-if="item.zk">
									<view class="con__box__list__item__box__item">
										<view class="">
											抵押方式
										</view>
										<view class="">
											{{item.diya}}
										</view>
									</view>
									<view class="con__box__list__item__box__item">
										<view class="">
											还款方式
										</view>
										<view class="">
											{{item.loan_method}}
										</view>
									</view>
									<view class="con__box__list__item__box__item">
										<view class="">
											抵押物信息
										</view>
										<view class="">
											{{item.diyawu}}
										</view>
									</view>
									<view class="con__box__list__item__box__item">
										<view class="">
											还款日
										</view>
										<view class="">
											{{item.day}}号
										</view>
									</view>
								</view>
							</view>
						</view>
						<u-empty v-else></u-empty>
					</view>
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	import arprogress from '@/components/ar-circle-progress/index.vue'
	import user from '@/api/_user.js'
	export default {
		components: {
			arprogress
		},
		data() {
			return {
				loading:true,
				percent: 0,
				tablist: [{
						name: '还款记录'
					},
					{
						name: '借款记录'
					},
				],
				curindex: 0,
				info:{}
			};
		},
		methods:{
			async getdata(){
				let res = await user.myDead()
				if(res.data.code==1){
					this.info=res.data.data
					this.info.credit.map(t=>{
						t.iszk=false
					})
					this.info.repayment.map(t=>{
						t.iszk=false
					})
					this.loading=false
				}
			}
		},
		onLoad() {
			this.getdata()
		}
	}
</script>

<style lang="scss">
	.con {
		.tip {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 24rpx;
			color: #626262;
			line-height: 24rpx;
			margin-bottom: 30rpx;
			text-align: center;
		}

		.num {
			font-family: DIN Next LT Pro;
			font-weight: bold;
			font-size: 48rpx;
			color: #1E1E1E;
			line-height: 35rpx;
			text-align: center;
		}

		.info {
			padding: 0 30rpx 36rpx;

			&__box {
				position: relative;

				&__bg {
					width: 690rpx;
					height: 146rpx;
					position: absolute;
					top: 0;
					left: 0;
				}

				&__yuan1 {
					width: 47rpx;
					height: 47rpx;
					background: #FFFFFF;
					border-radius: 50%;
					position: absolute;
					left: -24rpx;
					top: 51rpx;
				}

				&__yuan2 {
					width: 47rpx;
					height: 47rpx;
					background: #FFFFFF;
					border-radius: 50%;
					position: absolute;
					right: -22rpx;
					top: 51rpx;
				}

				&__con {
					display: flex;
					align-items: center;
					justify-content: center;

					&__item {
						width: 45%;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						height: 146rpx;

						&__num {
							font-family: DIN Next LT Pro;
							font-weight: bold;
							font-size: 32rpx;
							color: #1E1E1E;
							line-height: 24rpx;
							margin-bottom: 28rpx;
						}

						&__text {
							font-family: PingFang SC;
							font-weight: 500;
							font-size: 22rpx;
							color: #1E1E1E;
							line-height: 22rpx;
							opacity: 0.81;
						}
					}

					&__line {
						width: 2rpx;
						height: 28rpx;
						background: #3262FD;
						opacity: 0.28;
					}
				}
			}

			&__item {
				width: 49%;
				display: flex;
				align-items: flex-start;
				justify-content: center;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #161B1F;
				line-height: 30rpx;

				&__icon {
					width: 34rpx;
					height: 34rpx;
					margin-right: 19rpx;
				}
			}

			&__line {
				width: 2rpx;
				height: 28rpx;
				background: #F1F1F1;
			}
		}

		&__box {
			padding: 30rpx;

			&__tabs {
				height: 83rpx;
				border-radius: 20rpx;
				border: 3rpx solid #F5F5F5;
				display: flex;
				align-items: center;
				overflow: hidden;

				&__item {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 28rpx;
					color: #2C2C2C;
					line-height: 28rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					height: 83rpx;
					width: 50%;
					background-color: #fff;
				}

				.active {
					background-color: #F5F5F5;
				}
			}

			&__list {
				padding-top: 6rpx;

				&__item {
					padding: 40rpx 13rpx 0 14rpx;

					&__top {
						width: 100%;
						justify-content: space-between;
						padding-bottom: 30rpx;
						border-bottom: 1rpx solid #F4F4F4;
					}

					&__name {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #2C2C2C;
						line-height: 26rpx;
						margin-bottom: 17rpx;
					}

					&__time {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 22rpx;
						color: #888888;
						line-height: 18rpx;
					}

					&__num {
						font-family: PingFang SC;
						font-weight: 800;
						font-size: 22rpx;
						color: #313131;
						line-height: 22rpx;

						&__icon {
							width: 20rpx;
							height: 12rpx;
							margin-left: 8rpx;

						}

						.zk {
							transform: rotate(180deg);
						}
					}

					&__box {
						background: #F5F5F5;
						border-radius: 10rpx;
						padding: 14rpx 37rpx 30rpx 30rpx;

						&__item {
							display: flex;
							align-items: center;
							justify-content: space-between;
							height: 72rpx;
							font-family: PingFang SC;
							font-weight: 500;
							font-size: 24rpx;
							color: #2C2C2C;
							line-height: 72rpx;
							opacity: 0.8;
						}
					}
				}
			}
		}
	}

	.bb0 {
		border-bottom: 0;
	}
</style>